/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import db.JDBCUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author hk
 */
public class ProductInfoDaoImpl {
    
    public static void main(String[] args){
        List<ProductInfo> list;
        list = new ProductInfoDaoImpl().displayAllProductInfo();
        System.out.println("NYF");
    }
    
    public List<ProductInfo> displayAllProductInfo() {
        Connection conn=null;
        Statement stat=null;
        ResultSet rs=null;
        String sql="select * from ProductInfo";
        List<ProductInfo> list=new ArrayList<ProductInfo>();
        try{
            conn=JDBCUtil.getConnection();
            stat=conn.createStatement();
            rs=stat.executeQuery(sql);
            while(rs.next()){
                ProductInfo produc=new ProductInfo();           
                produc.setPID(rs.getInt("PID"));
                produc.setProductName(rs.getString("ProductName"));
                produc.setHardness(rs.getString("Hardness"));
                produc.setInventory(rs.getString("Inventory"));
                produc.setSizeDesc(rs.getString("SizeDesc"));
                produc.setThinkness(rs.getString("Thinkness"));
                list.add(produc);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            JDBCUtil.realeaseAll(rs, stat, conn);
        }
        return list;
         //To change body of generated methods, choose Tools | Templates.
    }
    public int updateProductInfo(ProductInfo Product) {
        String sql="UPDATE productinfo SET  PID=?, CID=?, OrderNumber=?,OrderTime=?,OrderDesc=? where OID=?";
        Connection conn=null;
        PreparedStatement pstat=null;
        ResultSet rs=null;
        
        int count=0;
        try{
            conn=JDBCUtil.getConnection();
            pstat=conn.prepareCall(sql);
            pstat.setInt(1,Product.getPID());
            pstat.setString(2,Product.getHardness());
            pstat.setString(3,Product.getInventory());
            pstat.setString(4,Product.getProductName());
            pstat.setString(5,Product.getSizeDesc());
            pstat.setString(6,Product.getThinkness());
            count=pstat.executeUpdate();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            JDBCUtil.realeaseAll(rs, pstat, conn);
        }
        return count;
    }
   public int inputProductInfo(ProductInfo Product) {
       
        String sql="insert  into orderinfo(OID,PID,CID,OrderNumber,OrderDesc) values(?,?,?,?,?)";
        Connection conn=null;
        PreparedStatement pstat=null;
        ResultSet rs=null;
        
        int count=0;
       try{
            conn=JDBCUtil.getConnection();
            pstat=conn.prepareCall(sql);
            pstat.setInt(1, Product.getPID());
            pstat.setString(2, Product.getHardness());
            pstat.setString(3, Product.getInventory());
            pstat.setString(4, Product.getProductName());
            pstat.setString(5, Product.getSizeDesc());
            pstat.setString(6, Product.getThinkness());                
            count=pstat.executeUpdate();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            JDBCUtil.realeaseAll(rs, pstat, conn);
        }
        return count;
    
    }
}
